//
//  WSTableViewCell.m
//  WSFramework
//
//  Created by zhangcong on 2018/3/31.
//  Copyright © 2018年 zhangcong. All rights reserved.
//

#import "WSTableViewCell.h"
#import "WSTableViewDelegate.h"

@interface WSTableViewCell ()


@end

@implementation WSTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code

    
}

- (void)update:(id)data {}

-(void) didSelectRowColumn:(NSUInteger) column {
    id datasource = [self getDataSource];
    if ([datasource conformsToProtocol:@protocol(WSTableViewDelegate)]) {
        SEL selAction = @selector(tableView:rowAtIndexPath:didSelectColumnAtIndex:);
        if ([datasource respondsToSelector:selAction])
            [(id <WSTableViewDelegate>) datasource tableView:[self getTableView] rowAtIndexPath:[self getCellIndexPath] didSelectColumnAtIndex:column];
    }
}

-(void) didSelectRowAction:(NSUInteger) action {
    [self didSelectRowAction:action data:nil];
}

-(void) didSelectRowAction:(NSUInteger) action data:(id) data {
    id datasource = [self getDataSource];
    if ([datasource conformsToProtocol:@protocol(WSTableViewDelegate)]) {
        SEL selAction = @selector(tableView:rowAtIndexPath:didAction:data:);
        if ([datasource respondsToSelector:selAction]) {
            [(id <WSTableViewDelegate>) datasource tableView:[self getTableView] rowAtIndexPath:[self getCellIndexPath] didAction:action data:data];
        }
    }
}

#pragma mark - 获取cell所在的 vc tableview indexpath
- (id)getDataSource {
    return [self getTableView].dataSource;
}
- (UITableView *)getTableView {
    UIView * view = self.superview;
    if ([view isKindOfClass:UITableView.class]) {
        return (UITableView *)view;
    }
    return (UITableView *) view.superview;;
}
- (NSIndexPath *)getCellIndexPath {
    return [[self getTableView] indexPathForCell:self];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
